// pages/offer/index.js
var App = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    banner: '',
    name: '', // 姓名
    phone: '', // 手机号
    measure: '' // 房屋面积
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBanner()

  },
  
 /**
   * 获取施工现场banner
   */
  getBanner: function() {
    let that = this;
    App._get('threesomes.pictures/index', {pos_id: 4}, function(res) {
      that.setData({
        banner: res.data.list[0].image.file_path
      });
    });
  },
  fillName(e){
    const that = this
    that.setData({
      name: e.detail.value
    })
  },
  fillPhone(e){
    const that = this
    that.setData({
      phone: e.detail.value
    })
  },
  fillMeasure(e){
    const that = this
    that.setData({
      measure: e.detail.value
    })
  },
  /**
   * 免费获取装修报价
   */
  getOffer(){
    const that = this
    let name = that.data.name
    let phone = that.data.phone
    let measure = that.data.measure
    let phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/
    if(name === ''){
      App.toastShow(that, "姓名不能为空", "icon_hint")
      return false;
    }else if(phone === ''){
      App.toastShow(that, "手机号不能为空", "icon_hint")
      return false;
    }else if(!phoneReg.test(phone)){
      App.toastShow(that, "请输入正确的手机号", "icon_hint")
      return false;
    }else if(measure === ''){
      App.toastShow(that, "房屋面积不能为空", "icon_hint")
      return false;
    }else{
      App._post_form('threesomes.consult/add', {name : name, phone: phone, area: measure}, function(res) {
        if(res.code == 1){
          that.setData({
            name: '',
            phone: '',
            measure: ''
          })
          App.toastShow(that, "提交成功，我们会尽快联系您", "icon_hint")
        }else{
          App.toastShow(that, "获取装修报价失败", "icon_hint")
        }
      });
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})